<template>
    <van-empty v-if="total === 0 && loadEnd" style="height: 100%;"></van-empty>
    <van-pull-refresh class="refresh-list" v-model="isRefresh" @refresh="onRefresh" v-else>
        <van-list
                style="height: 100%"
                v-model="loadingMore"
                :finished="finished"
                offset="50"
                :immediate-check="false"
                :finished-text="''"
                @load="onLoad">
            <slot/>
        </van-list>
    </van-pull-refresh>

</template>

<script>
    export default {
        name: "v-refresh",
        data() {
            return {
                isRefresh: false,
                loadingMore: false,
                finished: false,
                total: 0,
                loadEnd: false,
            }
        },
        created() {
            // console.log(this.$slots.default);
        },
        methods: {



            //刷新完成
            close(total,isFinished) {
                console.log(total);
                this.loadEnd = true;
                this.total = total;
                this.isRefresh = false;
                this.loadingMore = false;
                this.finished = isFinished;
            },
            //刷新
            onRefresh() {

                this.finished = false;
                this.$emit('on-refresh');
            },

            onLoadEnd(s, total) {

                this.total = total;
                this.loadingMore = false;
                this.finished = s;
            },

            //加载更多
            onLoad() {
                this.$emit('on-load', this.onLoadEnd);
            }
        }
    }
</script>
